package files;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Group {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader reader =
			new BufferedReader(new InputStreamReader(System.in));
		String in;
		in = "S# <mittelhdt.>";

		/*
		 * 2000: 	$b	...#
		 * 			$a	nic
		 * 			$r	_<...>
		 */

		// \Q...\E (quotiert alles, was zwischen \Q und \E steht). 
		String pre1 = Pattern.quote("");
		String post1 = Pattern.quote("#");
		String pre2 = Pattern.quote("");
		String post2 = Pattern.quote("");
		String pre3 = Pattern.quote(" <");
		String post3 = Pattern.quote(">");
		// +?: nicht gierig
		String something = "(.+?)";
		String before = "(";
		String after = ")?";

		String patString =
			before + pre1 + something + post1 + after + before + pre2
				+ something + post2 + after + before + pre3 + "(.+)"
				+ post3 + after;
		
		patString = "(.+?#)?(.+?)?( <.+?>)?";

		Pattern pattern = Pattern.compile(patString);

		Matcher m = pattern.matcher(in);
		if (m.matches()) {
			for (int i = 1; i <= m.groupCount(); i++) {
				System.out.println(m.group(i));
			}
		}

	}

}
